package com.qf;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.util.Scanner;

public class MQTest {
    public static void main(String[] args) throws Exception {
        //发送消息的步骤
        //1.创建消息生产者producer(DefaultMQProducer)，并制定生产者group
        DefaultMQProducer producer = new DefaultMQProducer("test-group");
        //2.指定Nameserver地址
        producer.setNamesrvAddr("127.0.0.1:9876");
        //3.启动producer
        producer.start();
        //4.创建Message对象，指定主题Topic、消息体
        Message message
                //指定库，表，内容
                = new Message("test-topic", "test0tag", "你好 MQ!!".getBytes());
        //5.发送消息
        SendResult send = producer.send(message);//发送同步消息,有返回结果
        System.out.println(send);
//6.关闭生产者producer
        producer.shutdown();
        System.out.println("abc");
        System.out.println("请输入");
        String s = new Scanner(System.in).nextLine();
        System.out.println(s);
    }
}
